home *** CD-ROM | disk | FTP | other *** search
- package views.Groups
- {
- import events.NavigationEvent;
- import flash.events.Event;
- import flash.events.KeyboardEvent;
- import flash.events.MouseEvent;
- import flash.ui.Keyboard;
- import flash.utils.getDefinitionByName;
- import model.PresentationModel;
- import mx.binding.Binding;
- import mx.binding.IWatcherSetupUtil;
- import mx.binding.utils.ChangeWatcher;
- import mx.containers.Canvas;
- import mx.controls.Alert;
- import mx.controls.Button;
- import mx.controls.TextInput;
- import mx.core.UIComponentDescriptor;
- import mx.core.mx_internal;
- import mx.events.FlexEvent;
- import mx.events.PropertyChangeEvent;
-
- public class PageNavigation extends Canvas
- {
- private static var _watcherSetupUtil:IWatcherSetupUtil;
-
- private var _bindings:Array;
-
- public var _bindingsByDestination:Object;
-
- [Bindable]
- private var _1456159669pageNavNextBtn:Button;
-
- [Bindable]
- private var _709108619pageNavPrevBtn:Button;
-
- private var lastPageNavTxt:String;
-
- public var _bindingsBeginWithWord:Object;
-
- public var myWatcher:ChangeWatcher;
-
- [Bindable]
- private var _1857328081presentationModel:PresentationModel;
-
- [Bindable]
- private var _2084171470pageNavStartBtn:Button;
-
- [Bindable]
- private var _209392814currPageText:String;
-
- [Bindable]
- private var _706983058pageNavTxtInput:TextInput;
-
- private var _watchers:Array;
-
- [Bindable]
- private var _203020107pageNavEndBtn:Button;
-
- private var _documentDescriptor_:UIComponentDescriptor;
-
- public function PageNavigation()
- {
- _documentDescriptor_ = new UIComponentDescriptor({
- "type":Canvas,
- "propertiesFactory":function():Object
- {
- return {
- "width":264,
- "height":36,
- "childDescriptors":[new UIComponentDescriptor({
- "type":Button,
- "id":"pageNavStartBtn",
- "events":{"click":"__pageNavStartBtn_click"},
- "propertiesFactory":function():Object
- {
- return {
- "buttonMode":true,
- "styleName":"pageNavStartBtn"
- };
- }
- }),new UIComponentDescriptor({
- "type":Button,
- "id":"pageNavPrevBtn",
- "events":{"click":"__pageNavPrevBtn_click"},
- "propertiesFactory":function():Object
- {
- return {
- "buttonMode":true,
- "styleName":"pageNavPrevBtn",
- "x":46
- };
- }
- }),new UIComponentDescriptor({
- "type":TextInput,
- "id":"pageNavTxtInput",
- "events":{"keyUp":"__pageNavTxtInput_keyUp"},
- "propertiesFactory":function():Object
- {
- return {
- "styleName":"pageNavTxtInput",
- "toolTip":"Type a number and press Enter",
- "x":92,
- "y":8,
- "width":80,
- "height":20
- };
- }
- }),new UIComponentDescriptor({
- "type":Button,
- "id":"pageNavNextBtn",
- "events":{"click":"__pageNavNextBtn_click"},
- "propertiesFactory":function():Object
- {
- return {
- "buttonMode":true,
- "styleName":"pageNavNextBtn",
- "x":172
- };
- }
- }),new UIComponentDescriptor({
- "type":Button,
- "id":"pageNavEndBtn",
- "events":{"click":"__pageNavEndBtn_click"},
- "propertiesFactory":function():Object
- {
- return {
- "buttonMode":true,
- "styleName":"pageNavEndBtn",
- "x":218
- };
- }
- })]
- };
- }
- });
- super();
- mx_internal::_document = this;
- this.width = 264;
- this.height = 36;
- this.horizontalScrollPolicy = "off";
- this.verticalScrollPolicy = "off";
- this.addEventListener("creationComplete",___Canvas1_creationComplete);
- }
-
- public static function set watcherSetupUtil(param1:IWatcherSetupUtil) : void
- {
- PageNavigation._watcherSetupUtil = param1;
- }
-
- private function message(param1:String) : void
- {
- Alert.show(param1,"Hint");
- }
-
- private function strToPageNum(param1:String) : int
- {
- var _loc2_:RegExp = null;
- var _loc3_:String = null;
- var _loc4_:int = 0;
- var _loc5_:Number = NaN;
- if("1" == param1)
- {
- return 0;
- }
- _loc2_ = /[^\w&]+/gi;
- _loc3_ = "";
- param1 = param1.replace(_loc2_,_loc3_);
- _loc4_ = int(param1.indexOf("&"));
- if(-1 != _loc4_)
- {
- param1 = param1.substring(0,_loc4_);
- }
- _loc5_ = Number(param1);
- if(isNaN(_loc5_))
- {
- return -1;
- }
- _loc5_ = Math.floor(_loc5_ / 2);
- if(_loc5_ > presentationModel.numPages - 1)
- {
- return presentationModel.numPages - 1;
- }
- if(0 > _loc5_)
- {
- return 0;
- }
- return int(_loc5_);
- }
-
- public function __pageNavNextBtn_click(param1:MouseEvent) : void
- {
- clickHandler(param1);
- }
-
- public function pageStringListener(param1:PropertyChangeEvent) : void
- {
- trace("pageString has changed");
- currPageText = presentationModel.pageString;
- }
-
- public function set presentationModel(param1:PresentationModel) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._1857328081presentationModel;
- if(_loc2_ !== param1)
- {
- this._1857328081presentationModel = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"presentationModel",_loc2_,param1));
- }
- }
-
- [Bindable(event="propertyChange")]
- public function get presentationModel() : PresentationModel
- {
- return this._1857328081presentationModel;
- }
-
- [Bindable(event="propertyChange")]
- public function get pageNavEndBtn() : Button
- {
- return this._203020107pageNavEndBtn;
- }
-
- [Bindable(event="propertyChange")]
- public function get pageNavPrevBtn() : Button
- {
- return this._709108619pageNavPrevBtn;
- }
-
- private function clickHandler(param1:Event) : void
- {
- if(-1 == presentationModel.numPages)
- {
- trace("-1 == numPages");
- message("Use \'Browse By Cover\' to choose a magazine.");
- return;
- }
- switch(param1.target)
- {
- case pageNavStartBtn:
- dispatchEvent(new NavigationEvent(NavigationEvent.START_PAGE,null,true));
- break;
- case pageNavPrevBtn:
- dispatchEvent(new NavigationEvent(NavigationEvent.PREV_PAGE,null,true));
- break;
- case pageNavNextBtn:
- dispatchEvent(new NavigationEvent(NavigationEvent.NEXT_PAGE,null,true));
- break;
- case pageNavEndBtn:
- dispatchEvent(new NavigationEvent(NavigationEvent.END_PAGE,null,true));
- break;
- case pageNavTxtInput:
- handleTextInput();
- }
- trace("clickHandler in PageNavigation for " + param1.target);
- }
-
- [Bindable(event="propertyChange")]
- private function get currPageText() : String
- {
- return this._209392814currPageText;
- }
-
- public function __pageNavStartBtn_click(param1:MouseEvent) : void
- {
- clickHandler(param1);
- }
-
- private function init() : void
- {
- myWatcher = ChangeWatcher.watch(this,["presentationModel","pageString"],pageStringListener);
- }
-
- public function __pageNavPrevBtn_click(param1:MouseEvent) : void
- {
- clickHandler(param1);
- }
-
- public function set pageNavPrevBtn(param1:Button) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._709108619pageNavPrevBtn;
- if(_loc2_ !== param1)
- {
- this._709108619pageNavPrevBtn = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavPrevBtn",_loc2_,param1));
- }
- }
-
- private function set currPageText(param1:String) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._209392814currPageText;
- if(_loc2_ !== param1)
- {
- this._209392814currPageText = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"currPageText",_loc2_,param1));
- }
- }
-
- public function __pageNavTxtInput_keyUp(param1:KeyboardEvent) : void
- {
- keyHandler(param1);
- }
-
- public function set pageNavEndBtn(param1:Button) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._203020107pageNavEndBtn;
- if(_loc2_ !== param1)
- {
- this._203020107pageNavEndBtn = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavEndBtn",_loc2_,param1));
- }
- }
-
- private function handleTextInput() : void
- {
- var _loc1_:String = null;
- var _loc2_:int = 0;
- if(-1 == presentationModel.numPages)
- {
- trace("-1 == numPages");
- message("Use \'Browse By Cover\' to choose a magazine.");
- return;
- }
- _loc1_ = pageNavTxtInput.text;
- if(_loc1_ != lastPageNavTxt)
- {
- _loc2_ = strToPageNum(_loc1_);
- if(-1 == _loc2_)
- {
- message("Only numbers and \'&\' will work. Try typing the page number, e.g. \'2\' or \'2 & 3\'");
- return;
- }
- dispatchEvent(new NavigationEvent(NavigationEvent.SELECT_PAGE,_loc2_,true));
- }
- }
-
- public function set pageNavStartBtn(param1:Button) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._2084171470pageNavStartBtn;
- if(_loc2_ !== param1)
- {
- this._2084171470pageNavStartBtn = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavStartBtn",_loc2_,param1));
- }
- }
-
- public function __pageNavEndBtn_click(param1:MouseEvent) : void
- {
- clickHandler(param1);
- }
-
- private function formatText(param1:int) : String
- {
- var _loc2_:String = null;
- var _loc3_:int = 0;
- if(-1 == param1 || -1 == presentationModel.numPages)
- {
- return "";
- }
- _loc2_ = "" + param1.toString();
- if(0 == param1)
- {
- _loc2_ = "" + 1;
- }
- else if(param1 == presentationModel.numPages - 1 && false == presentationModel.twoPageBack)
- {
- _loc2_ = "" + param1 * 2;
- }
- else
- {
- _loc3_ = param1 * 2;
- _loc2_ = "" + _loc3_ + " & " + ++_loc3_;
- }
- lastPageNavTxt = _loc2_;
- return _loc2_;
- }
-
- public function ___Canvas1_creationComplete(param1:FlexEvent) : void
- {
- init();
- }
-
- private function _PageNavigation_bindingExprs() : void
- {
- var _loc1_:* = undefined;
- _loc1_ = formatText(presentationModel.currentPage);
- }
-
- [Bindable(event="propertyChange")]
- public function get pageNavStartBtn() : Button
- {
- return this._2084171470pageNavStartBtn;
- }
-
- public function set pageNavTxtInput(param1:TextInput) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._706983058pageNavTxtInput;
- if(_loc2_ !== param1)
- {
- this._706983058pageNavTxtInput = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavTxtInput",_loc2_,param1));
- }
- }
-
- private function _PageNavigation_bindingsSetup() : void
- {
- var binding:Binding = null;
- if(!_bindings)
- {
- _bindings = [];
- }
- if(!_watchers)
- {
- _watchers = [];
- }
- binding = new Binding(this,function():String
- {
- var _loc1_:* = undefined;
- var _loc2_:* = undefined;
- _loc1_ = formatText(presentationModel.currentPage);
- return _loc1_ == undefined ? null : String(_loc1_);
- },function(param1:String):void
- {
- pageNavTxtInput.text = param1;
- },"pageNavTxtInput.text");
- _bindings[0] = binding;
- }
-
- [Bindable(event="propertyChange")]
- public function get pageNavTxtInput() : TextInput
- {
- return this._706983058pageNavTxtInput;
- }
-
- public function set pageNavNextBtn(param1:Button) : void
- {
- var _loc2_:Object = null;
- _loc2_ = this._1456159669pageNavNextBtn;
- if(_loc2_ !== param1)
- {
- this._1456159669pageNavNextBtn = param1;
- dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavNextBtn",_loc2_,param1));
- }
- }
-
- override public function initialize() : void
- {
- var target:PageNavigation = null;
- var watcherSetupUtilClass:Object = null;
- mx_internal::setDocumentDescriptor(_documentDescriptor_);
- _PageNavigation_bindingsSetup();
- target = this;
- if(_watcherSetupUtil == null)
- {
- watcherSetupUtilClass = getDefinitionByName("_views_Groups_PageNavigationWatcherSetupUtil");
- watcherSetupUtilClass["init"](null);
- }
- _watcherSetupUtil.setup(this,function(param1:String):*
- {
- return target[param1];
- },_bindings,_watchers);
- super.initialize();
- }
-
- [Bindable(event="propertyChange")]
- public function get pageNavNextBtn() : Button
- {
- return this._1456159669pageNavNextBtn;
- }
-
- private function keyHandler(param1:KeyboardEvent) : void
- {
- if(param1.keyCode == Keyboard.ENTER)
- {
- handleTextInput();
- }
- }
- }
- }
-
-